package cn.iocoder.yudao.module.alipay.controller.admin.infoslideshowtype;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.alipay.controller.admin.infoslideshowtype.vo.*;
import cn.iocoder.yudao.module.alipay.dal.dataobject.infoslideshowtype.InfoSlideshowTypeDO;
import cn.iocoder.yudao.module.alipay.convert.infoslideshowtype.InfoSlideshowTypeConvert;
import cn.iocoder.yudao.module.alipay.service.infoslideshowtype.InfoSlideshowTypeService;

@Tag(name = "管理后台 - 轮播图分类")
@RestController
@RequestMapping("/alipay/info-slideshow-type")
@Validated
public class InfoSlideshowTypeController {

    @Resource
    private InfoSlideshowTypeService infoSlideshowTypeService;

    @PostMapping("/create")
    @Operation(summary = "创建轮播图分类")
    @PreAuthorize("@ss.hasPermission('alipay:info-slideshow-type:create')")
    public CommonResult<Long> createInfoSlideshowType(@Valid @RequestBody InfoSlideshowTypeCreateReqVO createReqVO) {
        return success(infoSlideshowTypeService.createInfoSlideshowType(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新轮播图分类")
    @PreAuthorize("@ss.hasPermission('alipay:info-slideshow-type:update')")
    public CommonResult<Boolean> updateInfoSlideshowType(@Valid @RequestBody InfoSlideshowTypeUpdateReqVO updateReqVO) {
        infoSlideshowTypeService.updateInfoSlideshowType(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除轮播图分类")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('alipay:info-slideshow-type:delete')")
    public CommonResult<Boolean> deleteInfoSlideshowType(@RequestParam("id") Long id) {
        infoSlideshowTypeService.deleteInfoSlideshowType(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得轮播图分类")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('alipay:info-slideshow-type:query')")
    public CommonResult<InfoSlideshowTypeRespVO> getInfoSlideshowType(@RequestParam("id") Long id) {
        InfoSlideshowTypeDO infoSlideshowType = infoSlideshowTypeService.getInfoSlideshowType(id);
        return success(InfoSlideshowTypeConvert.INSTANCE.convert(infoSlideshowType));
    }

    @GetMapping("/list")
    @Operation(summary = "获取全部分类")
    @PreAuthorize("@ss.hasPermission('alipay:info-slideshow-type:query')")
    public CommonResult<List<InfoSlideshowTypeRespVO>> getInfoSlideshowTypeList() {
        List<InfoSlideshowTypeDO> list = infoSlideshowTypeService.getInfoSlideshowTypeList();
        return success(InfoSlideshowTypeConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得轮播图分类分页")
    @PreAuthorize("@ss.hasPermission('alipay:info-slideshow-type:query')")
    public CommonResult<PageResult<InfoSlideshowTypeRespVO>> getInfoSlideshowTypePage(@Valid InfoSlideshowTypePageReqVO pageVO) {
        PageResult<InfoSlideshowTypeDO> pageResult = infoSlideshowTypeService.getInfoSlideshowTypePage(pageVO);
        return success(InfoSlideshowTypeConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出轮播图分类 Excel")
    @PreAuthorize("@ss.hasPermission('alipay:info-slideshow-type:export')")
    @OperateLog(type = EXPORT)
    public void exportInfoSlideshowTypeExcel(@Valid InfoSlideshowTypeExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<InfoSlideshowTypeDO> list = infoSlideshowTypeService.getInfoSlideshowTypeList(exportReqVO);
        // 导出 Excel
        List<InfoSlideshowTypeExcelVO> datas = InfoSlideshowTypeConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "轮播图分类.xls", "数据", InfoSlideshowTypeExcelVO.class, datas);
    }

}
